var that;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: ['', '', ''],
    name: '',
    info: '',
    phone: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (options.i) {
      let page = getCurrentPages();
      page = page[page.length - 2];
      let { name, info, check, phone, province, countyName, city } = page.data.list[options.i], region = [province, city, countyName];
      this.setData({ name, check, info, phone, region, showregion: !0, edit: options.i })
    }
  },
  getown() {
    wx.chooseAddress({
      success: res => {
        console.log(res, 'res')
        this.setData({
          name: res.userName,
          phone: res.telNumber,
          info: res.detailInfo,
          showregion: !0,
          region: [res.provinceName, res.cityName, res.countyName]
        })
      }
    })
  },

  inputtap(e) {
    let { code } = e.currentTarget.dataset, { value } = e.detail,
      prop = code == 0 ? 'name' : code == 1 ? 'phone' : 'info';
    this.setData({ [prop]: value })
  },
  del(e) {
    let { code } = e.currentTarget.dataset, prop = code == 0 ? 'name' : code == 1 ? 'phone' : 'info';
    this.setData({ [prop]: '' })
  },
  pickchange(e) {
    let region = e.detail.value;
    this.setData({ region, showregion: !0 })
  },
  save() {
    var { showregion, region, name, phone, info } = this.data, err = '';
    if (info.length == 0) err = '联系地址'
    if (!showregion) err = '地区'
    if (phone.length != 11) err = '电话号码'
    if (name.length == 0) err = '收货人'
    if (err.length > 0) {
      wx.showModal({
        title: '提示',
        content: err + '填写有误',
        showCancel: !1,
      })
      return;
    }
    let item = { name, province: region[0], city: region[1], countyName: region[2], info, phone, check: 0 }, addresslist = wx.getStorageSync('address') || [], page = getCurrentPages();
    if (this.data.edit) {
      item.check = this.data.check;
      addresslist[this.data.edit] = item;
    } else {
      addresslist.push(item);
    }
    wx.setStorageSync('address', addresslist);
    page = page[page.length - 2];
    page.setData({ needgetaddress: !0 })
    wx.navigateBack()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})